
#set(totalAmount = customerReceivable.open_balance??0+customerReceivable.new_amount??0-customerReceivable.take_amount??0-customerReceivable.discount_amount??0)
	<div class="card">
		<div class="card-body">
			<div class="row text-center align-items-center">
				<div class="col-2">
					<span class="fw-bold text-secondary">期末剩余应收</span><br> <span class="fs-6 fw-bold text-danger">￥#number(totalAmount, "#.##")</span>
				</div>
				<div class="col">
					<span class="fs-3 text-secondary">=</span>
				</div>
				<div class="col">
					<span class="fw-bold text-secondary">期初应收款</span><br> <span class="fs-6 fw-bold text-secondary">￥#number(customerReceivable.open_balance??0, "#.##")</span>
				</div>
				<div class="col">
					<span class="fs-3 text-secondary">+</span>
				</div>
				<div class="col">
					<span class="fw-bold text-secondary">增加应收款</span><br> <span class="fs-6 fw-bold text-secondary">￥#number(customerReceivable.new_amount??0, "#.##")</span>
				</div>
				<div class="col">
					<span class="fs-3 text-secondary">-</span>
				</div>
				<div class="col">
					<span class="fw-bold text-secondary">收回应收款</span><br> <span class="fs-6 fw-bold text-secondary">￥#number(customerReceivable.take_amount??0, "#.##")</span>
				</div>
				<div class="col">
					<span class="fs-3 text-secondary">-</span>
				</div>
				<div class="col">
					<span class="fw-bold text-secondary">优惠金额</span><br> <span class="fs-6 fw-bold text-secondary">￥#number(customerReceivable.discount_amount??0, "#.##")</span>
				</div>
			</div>
		</div>
	</div>
	
<div class="card card-table mt-2">
	<div class="card-body page-body">
		<div class="row align-items-center oper-list">
			<div class="col-3">
			#if(session.hasOper(Permissions.fund_book_customerBill_export))
			<div class="btn-group" role="group" aria-label="Button group with nested dropdown">
			  <button type="button" class="btn btn-sm btn-outline-secondary" onclick="customerBill.export();">导出</button>
			  <div class="btn-group" role="group">
			    <button type="button" class="btn btn-sm btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"></button>
			    <ul class="dropdown-menu">
			      <li><a class="dropdown-item" href="javascript:void(0);" onclick="customerBill.exportLog();">导出记录</a></li>
			    </ul>
			  </div>
			</div>
			#end
			</div>
			<div class="col">
			#if(page.totalPage > 1)
			<div class="float-end">#@paginate(page.pageNumber, page.totalPage, "")</div>
			#end
			</div>
			
		</div>
	</div>
</div>

<table class="table table-hover table-bordered bg-white mt-1">
	<thead>
		<tr class="table-header">
			<th>客户名称</th>
			<th>客户分类</th>
			<th>结算账期</th>
			<th>期初应收款</th>
			<th>增加应收款</th>
			<th>收回应收款</th>
			<th>优惠金额</th>
			<th>期末应收款</th>
			<th style="width: 15%">操作</th>
		</tr>
	</thead>
	<tbody class="table-row" id="customerBill-list">
		#for (x : page.list)
		#set(customerInfo = x.customerInfo)
		<tr data-id="#(customerInfo.id)" id="customerBill-data-#(customerInfo.id)">
			<td><span class="fw-bold text-secondary">#(customerInfo.name)</span></td>
			<td>#(customerInfo.customerCategory.name??)</td>
			<td>#(customerInfo.payTypeName??) #if(customerInfo.pay_day && customerInfo.pay_day > 0) (<span class="text-warning">#(customerInfo.pay_day)天</span>) #end</td>
			<td><span >#number(x.open_balance??0, "#.##")</span> </td>
			<td><span >#number(x.new_amount??0, "#.##")</span> </td>
			<td><span >#number(x.take_amount??0, "#.##")</span> </td>
			<td><span >#number(x.discount_amount??0, "#.##")</span> </td>
			<td><span class="fw-bold text-secondary">#number(x.open_balance??0+x.new_amount??0-x.take_amount??0-x.discount_amount??0, "#.##")</span></td>
			<td>
				<button type="button" class="btn btn-sm sm-more btn-outline-primary" onclick="customerBill.show(#(customerInfo.id));">明细</button> 
			</td>
		</tr>
		#end

	</tbody>
</table>

<script type="application/javascript">
	
$(function() {
	// 初始化bootstrap相关组件
	common.initBootstrap();
	// 滚动表头处理
	common.tableFixedWidth();
	common.tableFixed();
	$(".main").scroll(function() {
		common.tableFixed();
	});
	$("#customerBill_pageNumber").val(#(page.pageNumber));
	
	$("#customerBill-list tr").on("dblclick", function() {
		customerBill.show($(this).attr("data-id"));
	});
	
});

customerBill.show = function(customerInfoId) {
	var startTime = $("#customerBill_search_start_time").val();
	var endTime = $("#customerBill_search_end_time").val();
	
	beekit.offcanvas("/fund/book/customerBill/show?customer_info_id="+customerInfoId+"&start_time="+startTime+"&end_time="+endTime);
};

customerBill.export = function() {
	beekit.confirmByUrl("/fund/book/customerBill/export", $("#customerBill-search-form").serialize(), "确定要导出对账单吗？", function(ret) {
		customerBill.exportLog(ret.targetId);
	});
}

customerBill.exportLog = function(targetId) {
	beekit.modal("/export/log/?targetId="+targetId);
}



</script>
